package org.shj.spark.operator;

import java.util.Arrays;
import java.util.List;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.VoidFunction;

public class IntersectionOperation {

	public static void main(String[] args) {
		SparkConf conf = new SparkConf().setMaster("local").setAppName("IntersectionOperation");
		JavaSparkContext sc = new JavaSparkContext(conf);
		
		List<String> list1 = Arrays.asList("xuruyun","GIGI", "linzhilin");
		List<String> list2 = Arrays.asList("caiyiling","zhuyin", "linzhilin");
		JavaRDD<String> nameRDD1 = sc.parallelize(list1);
		JavaRDD<String> nameRDD2 = sc.parallelize(list2);
		
		nameRDD1.intersection(nameRDD2).foreach(new VoidFunction<String>(){
			private static final long serialVersionUID = -7309176124664407119L;

			@Override
			public void call(String t) throws Exception {
				System.out.println(t);				
			}
			
		});
		
		sc.close();

	}

}
